package org.example.covid.entity;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class CountyEntity implements WritableComparable<CountyEntity> {

    private String state;
    private String county;
    private long cases; //确诊病例数

    public CountyEntity(String state, String county, long cases) {
        this.state = state;
        this.county = county;
        this.cases = cases;
    }

    public void set(String state, String county, long cases) {
        this.state = state;
        this.county = county;
        this.cases = cases;
    }

    public CountyEntity() {
    }

    /**
     * todo 排序规则：首先根据州排序，再根据病例数倒序
     *
     * @param o
     * @return
     */
    @Override
    public int compareTo(CountyEntity o) {
        int result;
        int i = state.compareTo(o.getState());
        if (i > 0) {
            result = 1;
        } else if (i < 0) {
            result =-1;
        } else {
            return cases > o.getCases() ? -1:(cases < o.getCases() ? 1:0);
        }
        return result;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeUTF(state);
        out.writeUTF(county);
        out.writeLong(cases);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        this.state = in.readUTF();
        this.county = in.readUTF();
        this.cases = in.readLong();
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getCounty() {
        return county;
    }

    public void setCounty(String county) {
        this.county = county;
    }

    public long getCases() {
        return cases;
    }

    public void setCases(long cases) {
        this.cases = cases;
    }

    @Override
    public String toString() {
        return state + '\t'  + county + '\t' + cases ;
    }
}
